package com.qf.day12.generic;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;

public class GenericDemo {
    public static void main(String[] args) {

        // 如果创建集合对象时，没有声明泛型参数，那么集合中可以放入任何对象
        Collection c = new ArrayList();
        Random random = new Random();

        c.add(new Student("万超岩",random.nextDouble()*100));
        c.add(new Student("臧家彤",random.nextDouble()*100));
        c.add(new Teacher("旭哥",random.nextDouble()*1000));
        c.add("哈哈");

        for (Object o : c) {
            System.out.println(o);
            // Exception in thread "main" java.lang.ClassCastException
            Student s = (Student) o;
            System.out.println(s.getScore());
        }


    }
}
